import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from pyecharts import Pie,Funnel,Boxplot,Map
plt.rcParams['font.sans-serif'] = ['SimHei'] # 在matplotlib中设置字体为SimHei黑体
plt.rcParams['axes.unicode_minus'] = False# 解决matplotlib坐标轴负号‘-’显示为方块问题
df = pd.read_csv(r"C:\Users\gcc\Desktop\jiangsu.csv")
def drawpie():#绘制江苏景点分布饼图
    lis = []
    lis = list(df['城市'])
    dic = {}
    for i in lis:
        dic[i] = dic.get(i, 0) + 1
    print(dic)
    key = dic.keys()
    value = dic.values()
    pie = Pie("江苏景点分布图",title_pos="center")
    pie.add("", key, value, is_label_show=True, is_more_utils=True, center=['50%', '60%'], is_legend_show=True,legend_top="8%",radius=["30%","75%"])
    pie.render(path="pie.html")
def drawFunnel():#绘制江苏景区分布漏斗图
    lis = []
    lis = list(df['城市'])
    dic = {}
    for i in lis:
        dic[i] = dic.get(i, 0) + 1
    dic=dict(sorted(dic.items(),key=lambda X:X[1],reverse=True))
    key=list(dic.keys())
    value=list(dic.values())
    pie=Funnel("景点数量漏斗图",title_pos="center")
    pie.add("",key[:10],value[:10],is_label_show=True,label_pos="inside",legend_top="6%")
    pie.render(path="funnel.html")
    print(dic)
def drawtbox():#h绘制景区和热度的箱型图
    df['热度']=df['热度'].astype(np.float)
    dic=df.loc[:,['星级','热度']]
    data=dic['热度'].values
    index=dic['星级'].values
    se=pd.Series(data=data,index=index)
    list5=se['5A景区'].tolist()
    list4=se['4A景区'].tolist()
    list3=se['3A景区'].tolist()
    list0=se['0'].tolist()
    print(list0)
    box=Boxplot('景区热度箱型图')
    x=['5A景区','4A景区','3A景区','其他景区']
    y=[]#存放5A，4A,3A,其他的热度
    y.append(list5)
    y.append(list4)
    y.append(list3)
    y.append(list0)
    _y=box.prepare_data(y)#转换数据
    box.add('热度',x,_y,item_color='green',xaxis_line_color='blue',yaxis_line_color='blue')
    box.render(path='box.html')
def drawboxs():#绘制景区销量箱型图
    df['销量'] = df['销量'].astype(np.float)
    dic = df.loc[:, ['星级', '销量']]
    data = dic['销量'].values
    index = dic['星级'].values
    se = pd.Series(data=data, index=index)
    list5 = se['5A景区'].tolist()
    list4 = se['4A景区'].tolist()
    list3 = se['3A景区'].tolist()
    list0 = se['0'].tolist()
    print(list0)
    box = Boxplot('景区销量箱型图')
    x = ['5A景区', '4A景区', '3A景区', '其他景区']
    y = []  # 存放5A，4A,3A,其他的热度s
    y.append(list5)
    y.append(list4)
    y.append(list3)
    y.append(list0)
    _y = box.prepare_data(y)  # 转换数据
    box.add('销量', x, _y, item_color='green', xaxis_line_color='blue', yaxis_line_color='blue')
    box.render(path='boxs.html')
def sumup(list,a):#统计某个市的5，4星级景区个数
    for i in list:
        if i=='5A景区' or i=='4A景区':
            a=a+1
    return a

def drawmap():#统计江苏省的5，4星级的景点个数热力图
    map = Map("江苏5A，4A级景点热力图",'江苏', width=1200, height=600)
    city = ['南京市', '苏州市', '常州市', '无锡市', '连云港市', '徐州市', '南通市', '淮安市', '盐城市', '扬州市', '镇江市', '泰州市', '宿迁市']
    dic = df.loc[:, ['星级', '城市']]
    data = dic['星级'].values
    index = dic['城市'].values
    se = pd.Series(data=data, index=index)
    dic={}
    list1=se['南京'].tolist()
    list2=se['苏州'].tolist()
    list3 = se['常州'].tolist()
    list4 = se['无锡'].tolist()
    list5 = se['连云港'].tolist()
    list6 = se['徐州'].tolist()
    list7 = se['南通'].tolist()
    list8 = list(se['淮安'])
    list9 = se['盐城'].tolist()
    list10 = se['扬州'].tolist()
    list11= se['镇江'].tolist()
    list12 = se['泰州'].tolist()
    list13= se['宿迁'].tolist()
    dic['南京']=sumup(list1,0)
    dic['苏州'] = sumup(list2, 0)
    dic['常州'] = sumup(list3, 0)
    dic['无锡'] = sumup(list4, 0)
    dic['连云港'] = sumup(list5, 0)
    dic['徐州'] = sumup(list6, 0)
    dic['南通'] = sumup(list7, 0)
    dic['淮安'] = sumup(list8, 0)
    dic['盐城'] = sumup(list9, 0)
    dic['扬州'] = sumup(list10, 0)
    dic['镇江'] = sumup(list11, 0)
    dic['泰州'] = sumup(list12, 0)
    dic['宿迁'] = sumup(list13, 0)
    #print(dic)
    values = list(dic.values())
    map.add('江苏', city, values, visual_range=[1, 14], maptype='江苏', is_visualmap=True, visual_text_color='#000',is_label_show=True)
    map.render(path="hotpicture.html")
drawmap()